<template>
  <div class="love-card" :class="sideTheme">
    <div class="love-card-head">
      <span>-------</span>
      <span class="name">荒</span>
      <span>❤️</span>
      <span class="name">YOLO.</span>
      <span>-------</span>
    </div>
    <div class="love-card-content">
      <img class="head-img" src="../../assets/images/huang.jpg" alt="" />
      <div class="heart-box">
        <img
          class="heart-img"
          src="../../assets/images/LoverCard/love-removebg-preview.png"
          alt=""
        />
      </div>
      <img class="head-img" src="../../assets/images/YOLO.jpg" alt="" />
    </div>
    <div class="love-card-footer">
      <span class="time">{{ year }}</span>
      <svg-icon class="time-icon" icon-class="nian" />
      <span class="time">{{ day }}</span>
      <svg-icon class="time-icon" icon-class="tian" />
      <span class="time">{{ hour }}</span>
      <svg-icon class="time-icon" icon-class="shi" />
      <span class="time">{{ minute }}</span>
      <svg-icon class="time-icon" icon-class="fen" />
      <span class="time">{{ second }}</span>
      <svg-icon class="time-icon" icon-class="miao" />
    </div>
  </div>
</template>

<script setup lang="ts" name="LoveCard">
import { useSettingsStore } from '@/store';
import { number } from 'echarts';
import moment from 'moment';
import { onMounted, onUnmounted, ref, computed } from 'vue';

const settingsStore = useSettingsStore();
const sideTheme = computed(() => settingsStore.sideTheme);

const year = ref();
const day = ref();
const hour = ref();
const minute = ref();
const second = ref();
let tiemInterval: ReturnType<typeof setInterval>;

const limitFormatTime = () => {
  let time = moment().diff(moment('2021-04-23')) / 1000;
  var y = Math.floor(time / 3600 / 24 / 365),
    d:number = Math.floor((time / 3600 / 24) % 365),
    h:number|string = Math.floor((time / 3600) % 24),
    m:number|string = Math.floor((time % 3600) / 60),
    s:number|string = Math.floor((time % 3600) % 60);
  if (h < 10) {
    h = '0' + h;
  }
  if (m < 10) {
    m = '0' + m;
  }
  if (s < 10) {
    s = '0' + s;
  }
  return {
    y: y, // 年
    d: d, // 天
    h: h, // 时
    m: m, // 分
    s: s, // 秒
  };
};
onMounted(() => {
  tiemInterval = setInterval(() => {
    let limit = limitFormatTime();
    year.value = limit.y;
    day.value = limit.d;
    hour.value = limit.h;
    minute.value = limit.m;
    second.value = limit.s;
  }, 1000);
});
onUnmounted(() => {
  clearInterval(tiemInterval);
});
</script>

<style lang="scss" scoped>
.love-card {
  margin-top: 20px;
  padding: 20px 24px;
  border-radius: 8px;
  box-shadow: 0 3px 8px 6px rgba(7, 17, 27, 0.05);
  background: rgba(255, 255, 255, 0.9);
}
.love-card-head {
  padding-bottom: 10px;
  font-size: 1.2em;
  width: 100%;
  display: inline-flex;
  justify-content: space-between;
  .name {
    width: 48px;
    display: inline-block;
    text-align: center;
  }
}
.love-card-content {
  display: flex;
  justify-content: center;
  align-content: center;
  .head-img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 3px solid #fff;
  }
  .heart-box {
    width: 35px;
    height: 80px;
    position: relative;
    .heart-img {
      position: absolute;
      top: 50%;
      left: 50%;
      margin-top: -14px;
      margin-left: -14px;
      width: 28px;
      height: 28px;
      animation: heartbeat 1.33s ease-in-out infinite;
    }
  }
}
.love-card-footer {
  margin-top: 20px;
  width: 100%;
  display: inline-flex;
  justify-content: center;
  align-content: center;
  .time {
    width: 40px;
    font-size: 16px;
    text-align: center;
    color: #4c4948;
  }
  .time-icon {
    width: 23px;
    height: 23px;
  }
}

@keyframes heartbeat {
  0%,
  100% {
    transform: scale(0.8);
  }
  50% {
    transform: scale(1.2);
  }
}

.theme-dark {
  background: rgba(0, 0, 0, 0.5) !important;
  color: #ffffffb3 !important;
  .time {
    color: #ffffffb3 !important;
  }
}
</style>
